	var IE = document.all;
	var oldNS = document.layers;
	var newNS = !document.all && document.getElementById;
	var opera = window.opera;

	function $(objId)
	{
		return document.getElementById(objId);
	}

	function preloadMenuImage(strRoot) 
	{
		imgMenuImage = new Image(1,1); 
		imgMenuImage.src=strRoot+'library/images/m_02.jpg';
	}

	function showHide(objID)
	{
		if ($(objID).style.display=='none')
		{
			$(objID).style.display='';
		}
		else
		{
			$(objID).style.display='none';
		}
	}

	function showSearchVaga()
	{
		if ($('divSearchVaga').style.display=='none')
		{
			$('divSearchVaga').style.display='block';
			$('divSearchCurriculo').style.display='none';
		}
	}
	function showSearchCurriculo()
	{
		if ($('divSearchCurriculo').style.display=='none')
		{
			$('divSearchVaga').style.display='none';
			$('divSearchCurriculo').style.display='block';
		}
	}

	function loadPopUp() 
	{
		window.open('popup.php', null, 'height=100,width=100,status=no,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=yes');
	}

	function closeSkyBanner() 
	{
		var objDivGeneral = $('divGeneral');
		var objDivSkyBanner = $('divDivSkyBanner');
		objDivGeneral.removeChild(objDivSkyBanner);
	}

	function loadSkyBanner(strFile, numWidth, numHeight) 
	{

		var objDivGeneral = $('divGeneral');

		numLeft = Math.floor( ( parseInt(objDivGeneral.clientWidth) - parseInt(numWidth) ) / 2 );

		var objDivSkyBanner = document.createElement("DIV");
		objDivSkyBanner.id = "divDivSkyBanner";
		objDivSkyBanner.style.position = "absolute";
		objDivSkyBanner.style.width = numWidth+"px";
		objDivSkyBanner.style.height = numHeight+"px";
		objDivSkyBanner.style.top = "-10px";
		objDivSkyBanner.style.left = numLeft+"px";
		objDivSkyBanner.style.zIndex = "999";

		objDivGeneral.appendChild(objDivSkyBanner);

		var so = new SWFObject(strFile, "objSWFSkyBanner", numWidth, numHeight, "8", "");
		so.addParam("scale", "noscale");
		so.addParam("wmode", "transparent");
		so.write("divDivSkyBanner");

	}

	function searchSimple()
	{
		if ($('palavra-chave').value.length < 3)
		{
			alert('A busca deve ser feita com pelo menos 3 letras.');
			$('palavra-chave').focus();
			return false;
		}
		else
		{
			return true;
		}
	}

	function openWindowPrint(strTarget)
	{
		window.open(strTarget, null, 'height=500,width=700,status=no,toolbar=yes,menubar=no,location=no,scrollbars=yes');
	}

	function openWindowCultural(idCultural, strRoot)
	{
		var objBody = document.body; 

		var objDivCover = document.createElement("DIV");
		objDivCover.id = "divCoverBody";
		objDivCover.style.width = "100%";
		objDivCover.style.height = objBody.parentNode.scrollHeight+'px';
		objDivCover.style.zIndex = "998";

		var objDivCoverBodyPhoto = document.createElement("DIV");
		objDivCoverBodyPhoto.id = "divCoverBodyContent";
		objDivCoverBodyPhoto.style.width = "100%";
		objDivCoverBodyPhoto.style.textAlign = "center";
		objDivCoverBodyPhoto.style.zIndex = "999";
		
		var objIframe = document.createElement("IFRAME");
		objIframe.style.marginTop = (window.document.documentElement.scrollTop + 50) + 'px';
		objIframe.style.backgroundColor = '#FFFFFF';
		objIframe.frameBorder = '0';
		objIframe.style.width = '405px';
		objIframe.style.height = '160px';
		objIframe.style.padding = '10px';
		objIframe.style.cursor = 'pointer';
		objIframe.src = strRoot+'cultural.php?id='+idCultural;

		objBody.appendChild(objDivCover);
		objDivCoverBodyPhoto.appendChild(objIframe);
		objBody.appendChild(objDivCoverBodyPhoto);
	}

	function createXMLHTTP() 
	{
		try 
		{
			ajax = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(e) 
		{
			try 
			{
				ajax = new ActiveXObject("Msxml2.XMLHTTP");
				alert(ajax);
			}
			catch(ex) 
			{
				try 
				{
					ajax = new XMLHttpRequest();
				}
				catch(exc) 
				{
					alert("Esse browser não tem recursos para uso do Ajax");
					ajax = null;
				}
			}
			return ajax;
		}
		
		var arrSignatures = ["MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
	
		for (var i=0; i < arrSignatures.length; i++) 
		{
			try 
			{
				var oRequest = new ActiveXObject(arrSignatures[i]);
				return oRequest;
			} 
			catch (oError) 
			{
		
			}
		}
		
		throw new Error("MSXML is not installed on your system.");
	}
	
	function submitRTEForm(strFormId, strTextResponseId)
	{

		objForm = $(strFormId);
		objResponse = $(strTextResponseId);

		if (validateForm(strFormId))
		{
			
			objResponse.innerHTML = 'aguarde o envio...';
			
			var oHTTPRequest = createXMLHTTP(); 
			oHTTPRequest.open("post", "../../library/util/ajaxSubmitRTEForm.php", true);
			oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			oHTTPRequest.onreadystatechange=function() 
			{
				if (oHTTPRequest.readyState==4)
				{
					objResponse.innerHTML = oHTTPRequest.responseText;
					objForm.reset();
				}
			}

			strRequest = '';
			for (i=0; i<objForm.elements.length; i++) 
			{
				if(objForm.elements[i].type != 'button' && objForm.elements[i].type != 'reset')
				{
					strValue = objForm.elements[i].value;
					if(objForm.elements[i].nodeName == 'SELECT' && objForm.elements[i].multiple)
					{
						strValue = '';
						for (j=0; j<objForm.elements(i).length; j++)
						{
							if (objForm.elements[i].options[j].selected)
							{
								strValue += objForm.elements[i].options[j].value + ', ';
							}
						}
					}
					strRequest += escape(objForm.elements[i].id) + '=' + escape(strValue) + '&';
				}
			}

			oHTTPRequest.send(strRequest);
		}
	}

	function ajaxSearchNeighborhood()
	{

		objText = $('txtBairro');
		objResponse = $('spnNeighborhood');

		if (objText.value.length >= 3)
		{
			
			objResponse.innerHTML = 'Procurando, aguarde...';
			
			var oHTTPRequest = createXMLHTTP(); 
			oHTTPRequest.open("post", "library/util/ajaxSearchNeighborhood.php", true);
			oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			oHTTPRequest.onreadystatechange=function() 
			{
				if (oHTTPRequest.readyState==4)
				{
					objResponse.innerHTML = oHTTPRequest.responseText;
				}
			}
			strRequest = 'bairro='+objText.value;

			oHTTPRequest.send(strRequest);
		}
		else
		{
			objResponse.innerHTML = '<b>Bairro inválido</b>';
		}
	}

//########################################################
//####################### Cultural #######################
//########################################################

	function getCultural(strDate, strRoot)
	{

		$('imgCulturalPreloader').style.display = 'block';
		objDiv = $('divCulturalBox');
		
		objDiv.innerHTML = '';
			
		var oHTTPRequest = createXMLHTTP(); 
		oHTTPRequest.open("post", strRoot+"library/util/ajaxCultural.php", true);
		oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oHTTPRequest.onreadystatechange=function() 
		{
			if (oHTTPRequest.readyState==4)
			{
				$('imgCulturalPreloader').style.display = 'none';
				objDiv.innerHTML = oHTTPRequest.responseText;
			}
		}
		oHTTPRequest.send('strDate='+strDate);
	}

	function showCultural(numSelected, numTotal)
	{
		
		for (i=1; i<=numTotal; i++)
		{
			if (i==numSelected)
			{
				$('ulCulturalItens_'+i).style.display = 'block';
				$('lnkCulturalItens_'+i).className = 'lnkSelected';
			}
			else
			{
				$('ulCulturalItens_'+i).style.display = 'none';
				$('lnkCulturalItens_'+i).className = '';
			}
		}

	}

//########################################################
//#################### Form Validation ###################
//########################################################

	function submitForm(targetForm)
	{
		if (validateForm(targetForm))
		{
			form = $(targetForm);
			form.submit();
		}
	}

	function getFieldName(strName)
	{
		return strName.slice(3);
	}

	function validateForm(targetForm)
	{
		form = $(targetForm);
		for (i=0; i<form.elements.length; i++) 
		{
			//if (form.elements.item(i).validation != 'none')	validationRemoveBlankSpace(form.elements.item(i));
			
			if (form.elements.item(i).style.display != 'none' && form.elements.item(i).nodeName != 'FIELDSET')
			{
				if (!validationRequieredField(form.elements.item(i)))
				{
					alert("O campo " + getFieldName(form.elements.item(i).id) + " é de preenchimento obrigatório.");
					setFocus(form.elements.item(i));
					return false;
				} 
	
				if (!validationMinLength(form.elements.item(i)))
				{
					alert("O campo " + getFieldName(form.elements.item(i).id) + " deve ter no mínimo " + form.elements.item(i).getAttribute('minLength') + " caracteres.");
					setFocus(form.elements.item(i));
					return false;
				}
	
				if (!validationMaxLength(form.elements.item(i)))
				{
					alert("O campo " + getFieldName(form.elements.item(i).id) + " deve ter no máximo " + form.elements.item(i).getAttribute('maxLength') + " caracteres.");
					setFocus(form.elements.item(i));
					return false;
				}
	
				if (!validationDateFormat(form.elements.item(i)))
				{
					alert("O campo " + getFieldName(form.elements.item(i).id) + " deve ter o formato dd/mm/aaaa.");
					setFocus(form.elements.item(i));
					return false;
				}
	
				if (!validationEmailFormat(form.elements.item(i)))
				{
					alert("O campo " + getFieldName(form.elements.item(i).id) + " deve ter um formato válido de e-mail.");
					setFocus(form.elements.item(i));
					return false;
				}
	
				if (!validationCurrencyFormat(form.elements.item(i)))
				{
					alert("O campo " + getFieldName(form.elements.item(i).id) + " deve ter um formato válido de moeda.");
					setFocus(form.elements.item(i));
					return false;
				}
	
				if (!validationNumberFormat(form.elements.item(i)))
				{
					alert("O campo " + getFieldName(form.elements.item(i).id) + " deve conter um número inteiro.");
					setFocus(form.elements.item(i));
					return false;
				}
	
				if (!validationDecimalFormat(form.elements.item(i)))
				{
					alert("O campo " + getFieldName(form.elements.item(i).id) + " deve conter um número decimal.");
					setFocus(form.elements.item(i));
					return false;
				}

				if (!validationCheckRequired(form.elements.item(i)))
				{
					alert("O campo " + getFieldName(form.elements.item(i).id) + " deve ser assinalado.");
					setFocus(form.elements.item(i));
					return false;
				}

			}
		}
		return true;
	}

	function validationRequieredField(targetField)
	{
		isValid = true;
		if (targetField.className == 'requiredfield')
		{
			if (targetField.value == "" || targetField.value == " ")
			{
				isValid = false;
			}
			if (targetField.value == "0" && (targetField.getAttribute('validation') != "number" && targetField.getAttribute('validation') != "decimal") )
			{
				isValid = false;
			}
		}
		if (targetField.className == 'inputRadio' && targetField.getAttribute('validation') == "required")
		{
			if (!targetField.checked)
			{
				isValid = false;
			}
		}
		return isValid;
	}

	function validationMinLength(targetField)
	{
		isValid = true;
		if (targetField.getAttribute('minLength') != '' && targetField.value.length > 0)
		{
			numMinLength = parseInt(targetField.getAttribute('minLength'));
			if (targetField.value.length < numMinLength)
			{
				isValid = false;
			}
		}
		return isValid;
	}

	function validationMaxLength(targetField)
	{
		isValid = true;
		if (targetField.getAttribute('maxLength') != '')
		{
			numMaxLength = parseInt(targetField.getAttribute('maxLength'));
			if (targetField.value.length > numMaxLength)
			{
				isValid = false;
			}
		}
		return isValid;
	}

	function validationDateFormat(targetField)
	{
		isValid = true;
		if (targetField.getAttribute('validation') != 'date')
		{
			return isValid;
		}
		if (targetField.value == '')
		{
			return isValid;
		}
		
		if (targetField.value.length > 10) isValid = false;
		if (targetField.value.length < 6) isValid = false;
		try
		{
			splitString = targetField.value.split("/")
			if (eval(splitString[0]) > 31) isValid = false;
			if (eval(splitString[1]) > 12) isValid = false;
			if (splitString[2] == '') isValid = false;
			if (eval(splitString[2]) < 1 || eval(splitString[2]) < 999) isValid = false;
		}
		catch (e)
		{
			 isValid = false;
		}		
		return isValid;
	}

	function validationEmailFormat(targetField)
	{
		isValid = true;
		if (targetField.getAttribute('validation') != 'email')
		{
			return isValid;
		}
		if (targetField.value == '')
		{
			return isValid;
		}

		var regExp = /^[a-z0-9_.-]{1,}@[a-z0-9_.-]{1,}\.[a-z]{2,3}(\.[a-z]{2,3})?\b/;
		if (!regExp.test(targetField.value)) isValid = false;

		return isValid;
	}

	function validationCurrencyFormat(targetField)
	{
		isValid = true;
		if (targetField.getAttribute('validation') != 'currency')
		{
			return isValid;
		}
		if (targetField.value == '')
		{
			return isValid;
		}

		var regExp = /^(R\$ *)?[0-9]{1,3}(\.[0-9]{3})*(\,[0-9]{1,2})?$/;
		if (!regExp.test(targetField.value)) isValid = false;

		return isValid;
	}

	function validationNumberFormat(targetField)
	{
		isValid = true;
		if (targetField.getAttribute('validation') != 'number')
		{
			return isValid;
		}
		try
		{
			if (eval(targetField.value) < 0) isValid = true;
		}
		catch (e)
		{
			 isValid = false;
		}
		return isValid;
	}

	function validationDecimalFormat(targetField)
	{
		isValid = true;
		if (targetField.getAttribute('validation') != 'decimal')
		{
			return isValid;
		}
		try
		{
			strAux = targetField.value.replace(",", ".");
			if (eval(strAux) < 0) isValid = true;
		}
		catch (e)
		{
			 isValid = false;
		}		
		return isValid;
	}

	function validationRemoveBlankSpace(targetField)
	{
		aux = targetField.value.length;
		for (j=0; j<aux; j++)
		{
			targetField.value = targetField.value.replace("  ", " ");
		}
	}

	function validationCheckRequired(targetField)
	{
		isValid = true;
		if (targetField.getAttribute('validation') != 'checkRequired')
		{
			return isValid;
		}
		if (!targetField.checked)
		{
			 isValid = false;
		}		
		return isValid;
	}

	function setFocus(targetField)
	{
		try
		{
			numAba = abaNumber;
		}
		catch (e)
		{
			numAba = 0;
		}
		if (numAba == 0)
		{
			targetField.focus();
			if (targetField.nodeName != 'SELECT') targetField.select();
		} 
		else
		{
			x=1;
			while (x<=numAba)
			{
				changeAba(x);
				try
				{
					targetField.focus();
					if (targetField.nodeName != 'SELECT') targetField.select();
					x = numAba+1;
				}
				catch (e)
				{
					x++;
				}
			}
		}
	}


//########################################################
//##################### Inputs Mask ######################
//########################################################

	function setMask(objTextBox, strMask, evtKeyPress) 
	{
		if (document.all)  // Internet Explorer
		{
			nTecla = evtKeyPress.keyCode;
		}
		else // Other
		{
			nTecla = evtKeyPress.which;
		}
	
		strValue = objTextBox.value;
		numLength = strValue.length;
	
		nextChar = strMask.charAt(numLength); 
		
		if (nTecla == 8 || nTecla == 46)
		{
			return nTecla;
		}
		else
		{
	
			if (nextChar != "9" && nextChar != "x" && nextChar != "X")
			{
				objTextBox.value = objTextBox.value + nextChar;
				nextChar = strMask.charAt(numLength+1); 
			}
	
			switch (nextChar) {
				case "9":
					if (nTecla > 47 && nTecla < 58) 
					{
						return nTecla;
					}
					else 
					{
						return false;
					}
					break
				case "x":
					if ((nTecla > 96 && nTecla < 123) || (nTecla > 64 && nTecla < 91)) 
					{
						objTextBox.value = objTextBox.value + String.fromCharCode(nTecla).toLowerCase();
						return false;
					}
					else 
					{
						return false;
					}
					break
				case "X":
					if ((nTecla > 96 && nTecla < 123) || (nTecla > 64 && nTecla < 91)) 
					{
						objTextBox.value = objTextBox.value + String.fromCharCode(nTecla).toUpperCase();
						return false;
					}
					else 
					{
						return false;
					}
					break
			}
		}
	}

	function setMaskCurrency(objTextBox, e)
	{
		SeparadorMilesimo = '.';
		SeparadorDecimal = ',';
		var sep = 0;
		var key = '';
		var i = j = 0;
		var len = len2 = 0;
		var strCheck = '0123456789';
		var aux = aux2 = '';
		var whichCode = (window.Event) ? e.which : e.keyCode;
		if (whichCode == 13) return true;
		key = String.fromCharCode(whichCode); // Valor para o código da Chave
		if (strCheck.indexOf(key) == -1) return false; // Chave inválida
		len = objTextBox.value.length;
		for(i = 0; i < len; i++)
			if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) break;
		aux = '';
		for(; i < len; i++)
			if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) aux += objTextBox.value.charAt(i);
		aux += key;
		len = aux.length;
		if (len == 0) objTextBox.value = '';
		if (len == 1) objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
		if (len == 2) objTextBox.value = '0'+ SeparadorDecimal + aux;
		if (len > 2) {
			aux2 = '';
			for (j = 0, i = len - 3; i >= 0; i--) {
				if (j == 3) {
					aux2 += SeparadorMilesimo;
					j = 0;
				}
				aux2 += aux.charAt(i);
				j++;
			}
			objTextBox.value = '';
			len2 = aux2.length;
			for (i = len2 - 1; i >= 0; i--)
			objTextBox.value += aux2.charAt(i);
			objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
		}
		return false;
	}

	function setMultiple(objTarget, numMax)
	{

		numCount = 0;
		for (i=0; i<objTarget.options.length; i++) 
		{
			if (objTarget.options[i].selected) 
			{
				if (numCount >= numMax)
				{
					objTarget.options[i].selected = false;
				}
				numCount++;
			}
		}

	}


//########################################################
//################### AJAX FILTER COMBO ##################
//########################################################


function ajaxFilterCombo(strParent, strTarget, strTable, strFieldFK, strFieldLabel, strFieldValue, idSelected, strPath)
{
	objParent = $(strParent);
	objTarget = $(strTarget);
	objParentValue = objParent.value;

	ajaxSetOptions(strTarget, "<option>Carregando...</option>", true);

	var oHTTPRequest = createXMLHTTP(); 
	oHTTPRequest.open("post", strPath+"cms/util/ajaxFilterDropDown.php", true);
	oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	oHTTPRequest.onreadystatechange=function() 
	{
		if (oHTTPRequest.readyState==4)
		{
			objTarget.disabled = false;
			window.setTimeout(function(){ajaxSetOptions(strTarget, oHTTPRequest.responseText, false)}, 100);
		}
	}
	strPost = 	"strValueCompare=" 	+ objParentValue + 
				"&strFieldFK=" 		+ strFieldFK + 
				"&strFieldLabel=" 	+ strFieldLabel + 
				"&strFieldValue=" 	+ strFieldValue + 
				"&strTable=" 		+ strTable + 
				"&idSelected=" 		+ idSelected;
	oHTTPRequest.send(strPost);
}

function ajaxSetOptions(strTarget, strReturn, bolDisabled)
{
	objTarget = $(strTarget);
	objParent = objTarget.parentNode;
	objTarget.disabled = bolDisabled;
	strReference = '#reference#';

	strReturn = unescape(strReturn);
	strReturn = strReturn.replace(/\+/g, ' ');

	objClone = objTarget.cloneNode(false);
	objTarget.innerHTML = '';

	objTarget = $(strTarget);

	if(document.all)
	{
		arrOptions = strReturn.split('</option>');
		idSelected = 0;
		for	(i=0; i<arrOptions.length-1; i++)
		{
			strOption = arrOptions[i] + '</option>';
			strOption = strOption.replace(/\n/, '');
			strOption = strOption.replace(/\r/, '');
			objOption = document.createElement(strOption);
			if (arrOptions[i].indexOf('selected') > 0) idSelected = i;
			objOption.text = arrOptions[i].replace(/<option(.*)>/, '');
			objTarget.add(objOption);
		}
		objTarget.options[idSelected].selected = true;
	}
	else
	{
		objTarget.innerHTML = strReturn;
	}
}

